<template>
  <main-layout>
    <header>
      <van-nav-bar
        title="买家"
        right-arrow
        @click-right="switchEvt"
        :border="false"
      >
        <template #right>
          <span>我是卖家</span>
          <img class="switch" src="../../images/switch.jpg" />
        </template>
      </van-nav-bar>
    </header>
    <div class="content">
      <div class="user-info" @click="$router.push('mine/info')">
        <div class="profile">
          <img src="../../images/log.jpg" alt="" />
        </div>

        <div class="user-name">
          <h4>{{userId}}</h4>
          <van-icon name="edit" />
          <p>精品宠物交易平台</p>
        </div>
      </div>
      <!-- 微信通知 -->
      <div class="wechat-info">
        <div class="pic">
          <img src="../../images/wechat.png" alt="" />
        </div>
        <div class="text">
          <h4>微信通知</h4>
          <p>开启后可及时查看消息和订单状态</p>
        </div>
        <div class="detail">我要开启 <van-icon name="arrow" /></div>
      </div>
      <!-- 我的订单 -->
      <div class="order">
        <div class="order-head">
          <van-nav-bar>
            <template #left>
              <span>我的订单</span>
            </template>
            <template #right>
              <span>预售订单</span>
              <van-icon name="arrow" size="18" color="black" />
            </template>
          </van-nav-bar>
        </div>
        <div class="order-content" v-for="it in orderInfo" :key="it.text">
          <i :class="it.icon"></i>
          <span>{{ it.text }}</span>
        </div>
      </div>
      <!-- 积分 -->
      <div class="points">
        <div class="pic">
          <img src="../../images/coin.png" alt="" />
        </div>
        <div class="text">
          <h4>0</h4>
          <p>我的当前积分</p>
        </div>
        <div class="detail">积分明细 <van-icon name="arrow" /></div>
      </div>
      <!-- 常用信息 -->
      <div class="common-info">
        <div class="info-head">
          <van-nav-bar>
            <template #left>
              <span>常用信息</span>
            </template>
          </van-nav-bar>
        </div>
        <div class="info-content" v-for="it in commonInfo" :key="it.icon">
          <i :class="it.icon"></i>
          <span>{{ it.text }}</span>
        </div>
      </div>

      <div class="more">
        <div class="more-head">
          <van-nav-bar>
            <template #left>
              <span>更多服务</span>
            </template>
          </van-nav-bar>
          <div class="more-content" v-for="it in serviceInfo" :key="it.text">
            <i :class="it.icon"></i>
            <span>{{ it.text }}</span>
          </div>
        </div>
      </div>
    </div>
  </main-layout>
</template>

<script>
export default {
  data() {
    return {
      orderInfo: [
        { icon: "unpaid", text: "待支付" },
        { icon: "undelivered", text: "待发货" },
        { icon: "delivered", text: "已发货" },
        { icon: "uncomment", text: "待评价" },
        { icon: "refund", text: "退款/仲裁" },
      ],

      commonInfo: [
        { icon: "favorate", text: "我的收藏" },
        { icon: "history", text: "历史记录" },
        { icon: "coupon", text: "领券中心" },
        { icon: "address", text: "收货地址" },
      ],

      serviceInfo: [
        { icon: "agreement", text: "购宠协议" },
        { icon: "statement", text: "平台声明" },
        { icon: "privicy", text: "隐私政策" },
        { icon: "feedback", text: "意见反馈" },

        { icon: "online", text: "在线客服" },
        { icon: "hotline", text: "客服热线" },
        { icon: "onhelp", text: "用户帮助" },
        { icon: "setting", text: "我的设置" },
      ],

      userId: ''
    };
  },
  methods: {
    switchEvt() {
      this.$router.push("./mine/seller");
    },
  },
  created(){
    // 修改成功提示
    if(this.$route.query.code*1 === 200){
      this.$toast({
          message: '修改成功',
          position: 'bottom'
      })
    }
    // 获取；用户账号昵称信息
    let res = JSON.parse(sessionStorage.getItem('userInfo'))
    if(res){
      this.userId = res.name
      return
    }
    // 如果没有设置昵称，显示手机号
    if(!!JSON.parse(localStorage.getItem('user-phone'))){
          this.userId = JSON.parse(localStorage.getItem('user-phone'))
    }  else {
          this.userId = JSON.parse(sessionStorage.getItem("vuex")).common.userInfo.id
    }

   
  }
};
</script>

<style lang="less" scoped>
.roundBox() {
  background-color: #fff;
  border-radius: 8px;
  margin: 12px 8px;
  overflow: hidden;
}

.icons(){
    > i{
      display: block;
      height: 54px;
      background-position: center center;
      background-size: 32px;
      background-repeat: no-repeat;
    }
    > span {
      font-size: 0.7rem;
      display: block;
      height: 16px;
      text-align: center;
      color: #545456;
    }
}

header {
  display: block;
  height: 46px;
  .switch {
    width: 14px;
    height: 14x;
    margin-left: 4px;
  }
}

.content {
  display: block;
  overflow-x: hidden;
  height: calc(100% - 46px);
  .user-info {
    background: #fff;
    height: 70px;
    padding: 15px 0;
    overflow: hidden;
    .profile {
      overflow: hidden;
      width: 70px;
      height: 70px;
      border-radius: 50%;
      margin: 0 20px;
      float: left;
      img{
        width: 100%;
        width: 100%;
        opacity: 0.4;
      }
    }
    .user-name {
      float: left;
      margin-top: 8px;
      h4 {
        font-size: 0.9rem;
        display: inline-block;
        margin: 0 0;
      }
      p {
        color: #666;
        font-size: 0.7rem;
      }
    }
  }
  .wechat-info {
    .roundBox();
    height: 80px;
    .pic{
       float: left;
       overflow: hidden;
       width: 45px;
       height: 45px;
       border-radius: 50%;
       margin: 14px 10px;
      img{
        width: 100%;
        height: 100%;
      }
    }
     .text{
       float: left;
       line-height: 0;
       margin-top: 10px;
       font-size: .85rem;
       p{
         color: #b0b0b0;
         font-size: .6rem;
         line-height: 18px;
       }
     }
     .detail{
       float: right;
       margin: 8px 6px;
       font-size: .9rem;
     }
  }
  .order {
    @orderIcons: unpaid undelivered delivered uncomment refund;
    //  定义一个方法
    .orderLoop(@orderIndex:1) when (@orderIndex <=5){
      @orderIcon: extract(@orderIcons, @orderIndex);

      > i{
        &.@{orderIcon}{
          background-image:url('../../images/mine/@{orderIcon}.png')
        }
      }
      .orderLoop(@orderIndex + 1)
    }
    //  定义一个方法
    height: 120px;
    .roundBox();
    .order-content{
      float: left;
      width: 20%;
      .icons();
      .orderLoop()
    }
    
  }
   /*积分明细 */
   .points{
     .roundBox();
     height: 80px;
     background-color: #fdd42b;
     .pic{
       float: left;
       overflow: hidden;
       width: 45px;
       height: 45px;
       border-radius: 50%;
       margin: 14px 10px;
       img{
         width: 100%;
         height: 100%;
       }
     }
     .text{
       float: left;
       line-height: 0;
       margin-top: 10px;
       p{
         font-size: .6rem;
       }
     }
     .detail{
       float: right;
       margin: 8px 6px;
       font-size: .9rem;
     }
   }
    /*常用信息 */
  .common-info {
  @comIcons: favorate history coupon address;
  //  定义一个方法
  .comLoop(@comIndex:1) when (@comIndex <=4){
    @comIcon: extract(@comIcons, @comIndex);

    > i{
      &.@{comIcon}{
        background-image:url('../../images/mine/@{comIcon}.png')
      }
    }
    .comLoop(@comIndex + 1)
  }
  //  定义一个方法

    .roundBox();
    height: 120px;
    .info-content{
      float: left;
      width:25%;
      .icons();
      .comLoop()
    }
  }
  
  /**更多信息 */
  .more {
    @favIcons: agreement statement privicy feedback online hotline onhelp setting;
  //  定义一个方法
  .moreLoop(@favIndex:1) when (@favIndex <=8){
    @favIcon: extract(@favIcons, @favIndex);

    > i{
      &.@{favIcon}{
        padding-bottom: 10px;
        background-image:url('../../images/mine/@{favIcon}.png')
      }
    }
    .moreLoop(@favIndex + 1)
  }
  //  定义一个方法
    .roundBox();
    height: 220px;
    .more-content{
      float: left;
      width:25%;
      .icons();
      .moreLoop()
    }
  }
}
</style>
